/***************************************************************************************************
  *Copyright(C),2010-2017,Sumscope
  *FileName	:  pinyin_search_key.h
  *Author	:  scofined.qi
  *Version	:  1.0
  *Date		:  2017/06/04
  *Desc		:  //用于主要说明此程序文件完成的主要功能
  *Relation :  
  *Others	:  //其他内容说明
  *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
  *History	:  //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
***************************************************************************************************/
#pragma once

namespace qb{
	namespace base{
		namespace internal{

			struct InverseKey3{		// 取代wstring,减少内存开销
				typedef InverseKey3 ThisType;
				wchar_t	code[4];
			public:
				InverseKey3(){
					code[0] = 0; code[1] = 0;
					code[2] = 0; code[3] = 0;
				}
				inline wchar_t Upper(wchar_t c)const{ return (c >= 'a'&&c <= 'z') ? (c-32) : c; }
				InverseKey3(const ThisType& ik){
					code[0] = ik.code[0];
					code[1] = ik.code[1];
					code[2] = ik.code[2];
					code[3] = ik.code[3];
				}
				InverseKey3(const wchar_t* str, int len){
					code[0] = Upper(str[0]); code[1] = Upper(str[1]); code[2] = Upper(str[2]);
					code[3] = len >= 4 ? Upper(str[3]) : 0;
				}
				InverseKey3(wchar_t first, wchar_t mid, wchar_t last){
					code[0] = Upper(first); code[1] = Upper(mid); code[2] = Upper(last); code[3] = 0;
				}
				InverseKey3(wchar_t first, wchar_t mid, wchar_t last,wchar_t fourth){
					code[0] = Upper(first); code[1] = Upper(mid); code[2] = Upper(last); code[3] = Upper(fourth);
				}
				inline unsigned int GetHash()const{return ((code[0] << 16) | code[1]) | (code[2] << 8);}
				ThisType& operator=(const ThisType& ik)
				{
					code[0] = ik.code[0];
					code[1] = ik.code[1];
					code[2] = ik.code[2];
					code[3] = ik.code[3];
					return *this;
				}
				bool operator==(const ThisType& ik)const{
					return code[0] == ik.code[0] && code[1] == ik.code[1] && code[2] == ik.code[2] && code[3] == ik.code[3];
				}
				bool operator<(const ThisType& ik)const{
					if (code[0] != ik.code[0])return code[0] < ik.code[0];
					if (code[1] != ik.code[1])return code[1] < ik.code[1];
					if (code[2] != ik.code[2])return code[2] < ik.code[2];
					if (code[3] != ik.code[3])return code[3] < ik.code[3];
					return false;
				}
			};
			typedef InverseKey3 InverseKey;
		}
	}
}
